/*
 * PACKAGE NAME: com.jodinfo.outmirror.implementation.offmessage.service
 * FILE    NAME: OffMessageDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.service.impl;


import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jodinfo.outmirror.Exception.OffMessageException;
import com.jodinfo.outmirror.dao.OffMessageDao;
import com.jodinfo.outmirror.entity.OffMessageEntity;
import com.jodinfo.outmirror.service.OffMessageDmlService;

/**
 * OffMessageDmlService实现
 * @author ZhangYuanYuan
 * @date 2016年12月30日 上午9:08:32
 * @version <b>1.0.0</b>
 */
@Service(value="offMessageDmlService")
@CacheConfig(cacheNames={"OffMessage"})
public class OffMessageDmlServiceImpl implements OffMessageDmlService {

 private static final Logger logger = LoggerFactory.getLogger(OffMessageDmlServiceImpl.class);

 
	@Resource(name="offMessageDao")
	private OffMessageDao offMessageDao;
	

	/** 
	 * 
	 * @author ZhangYuanYuan
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.offmessage.OffMessageDmlService#addOffMessage(OffMessageEntity offMessageEntity)
	 * @param OffMessageEntity offMessageEntity
	 * @return int
	 */
	@Transactional(rollbackFor = Exception.class) 
	@CacheEvict(allEntries=true,beforeInvocation=true)
	public int addOffMessage(OffMessageEntity offMessageEntity) {
		int i = 0;
		try{
			i = offMessageDao.add(offMessageEntity);
		}catch(Exception e){
			logger.error(e.getMessage());
			throw new OffMessageException("OffMessageEntity插入数据异常,",e.getMessage());
		}
		return i;
	}
	/** 
	 * 
	 * @author ZhangYuanYuan
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.offmessage.OffMessageDmlService#updateOffMessage(OffMessageEntity offMessageEntity)
	 * @param OffMessageEntity offMessageEntity
	 * @return int
	 */
	@Transactional(rollbackFor = Exception.class)
	@CacheEvict(allEntries=true,beforeInvocation=true)
	public int updateOffMessage(OffMessageEntity offMessageEntity) {
	
		int i = 0;
		try{
			i =  offMessageDao.update(offMessageEntity);;
		}catch(Exception e){
			logger.error(e.getMessage());
			throw new OffMessageException("OffMessageEntity更新数据异常,",e.getMessage());
		}
		return i;
	}
	
	/**
	 * 批量插入List<OffMessageEntity> offMessageEntityList
	 * @author shensu
	 * @date 2016年12月30日 上午9:11:48
	 * @param List<OffMessageEntity> offMessageEntityList
	 * @return int
	 */
	@Transactional(rollbackFor = Exception.class) 
	@CacheEvict(allEntries=true,beforeInvocation=true)
	public int batchAddOffMessage(List<OffMessageEntity> offMessageEntityList) {
		int i = 0;
		try{
			i =  offMessageDao.adds(offMessageEntityList);
		}catch(Exception e){
			logger.error(e.getMessage());
			throw new OffMessageException("OffMessageEntity更新数据异常,",e.getMessage());
		}
		return i;
	}
	
	/**
	 * 批量更新List<OffMessageEntity> offMessageEntityList
	 * @author shensu
	 * @date 2016年12月30日 上午9:11:48
	 * @param List<OffMessageEntity> offMessageEntityList
	 * @return int
	 */
	@Transactional(rollbackFor = Exception.class) 
	@CacheEvict(allEntries=true,beforeInvocation=true)
	public int batchUpdateOffMessage(List<OffMessageEntity> offMessageEntityList) {
		int i = 0;
		try{
			i =  offMessageDao.updates(offMessageEntityList);
		}catch(Exception e){
			logger.error(e.getMessage());
			throw new OffMessageException("OffMessageEntity更新数据异常,",e.getMessage());
		}
		return i;
	}
	
}

